package com.ibeeking.found.auth.api.feign.fallback;

import com.ibeeking.found.auth.api.common.dto.LoginUserDTO;
import com.ibeeking.found.auth.api.common.query.AccountLoginQuery;
import com.ibeeking.found.auth.api.feign.GlobalLoginClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GlobalLoginFallbackFactory implements FallbackFactory<GlobalLoginClient> {
    @Override
    public GlobalLoginClient create(Throwable throwable) {
        return new GlobalLoginClient() {

            @Override
            public ResponseResult<LoginUserDTO> queryAccountLogin(AccountLoginQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，用户登录失败。" + throwable.getMessage());
            }

        };
    }
}
